﻿using Common.GeneralClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using TCPIPControl.StructHelper;
using Common.DBOper;

namespace Common
{
    public class SaveData
    {
        OperateAccDataInfo op_acc = new OperateAccDataInfo();
        OperateDisplacementDataInfo op_displace = new OperateDisplacementDataInfo();
        OperateSlowSignalInfo op_slow = new OperateSlowSignalInfo();
        OperateSpeedDataInfo op_speed = new OperateSpeedDataInfo();
        OperateSamplingConfigInfo op_vol = new OperateSamplingConfigInfo();

        OperateData oper_data = new OperateData();
        OperateTest oper_test = new OperateTest();
        OperationText optxt = new OperationText();
        OperRunSet operunset = new OperRunSet();
        Common.DBOper.OperateChannel opchannel = new Common.DBOper.OperateChannel();
        public void SaveString(string datas)
        {

        }

        public void SaveACQParametersConfig(ACQParametersConfig datas)
        {

        }

        public void SaveAccData()
        {
            do
            {
                try
                {

                if (Mdl_Class.IsQuitProgram) 
                {
                    break;
                }

                    //if (Mdl_Class.accdatalist.Count > Mdl_Class.AverageNO)
                    //{
                    //    Mdl_Class.TestProgress = Mdl_Class.AverageNO;

                    //}
                    //else 
                    //{
                    //    Mdl_Class.TestProgress = Mdl_Class.accdatalist.Count;
                    //}

                if (Mdl_Class.accdatalist.Count > 0)
                {
                    List<Cls_Data> datalist = new List<Cls_Data>();
                    List<float> AccelerationTimewavelist = new List<float>();
                    //for (int i = 0; i < Mdl_Class.AverageNO; i++)
                    //{
                    int i = 0;
                    switch (Mdl_Class.LineNO)
                    {

                        case 256:
                            Acceleration_256 accdate_256 = (Acceleration_256)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_256.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_256.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_256;
                                Mdl_Class.onlinchannelData.Add(accdate_256);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_256.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_256);
                                }
                                if (accdate_256.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_256);
                                }
                                if (accdate_256.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_256);
                                }
                                if (accdate_256.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_256);
                                }
                            }

                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_256.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_256.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_256.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_256.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_256 = new Cls_Data();
                                cls_data_256._1_3octavedB = accdate_256._1_3octavedB.ToList();
                                cls_data_256.AccelerationFFTAmpDB = accdate_256.accelerationFFTAmpDB.ToList();
                                cls_data_256.AccelerationFFTAmpDB_length = accdate_256.accelerationFFTAmpDB.Length;
                                cls_data_256.AccelerationTimewave = accdate_256.accelerationTimewave.ToList();
                                cls_data_256.AccelerationTimewave_Length = accdate_256.accelerationTimewave.Length;
                                cls_data_256.ChannelId = accdate_256.ChannelId;
                                cls_data_256.HighdB = accdate_256.highdB;
                                cls_data_256.LowdB = accdate_256.lowdB;
                                cls_data_256.TestId = Mdl_Class.TestId;
                                cls_data_256.TotaldB = accdate_256.totaldB;
                                cls_data_256.VelocityRMS = accdate_256.velocityRMS;
                                cls_data_256.TestTime = accdate_256.Year.ToString() + "/" + accdate_256.Month.ToString() + "/" + accdate_256.Day.ToString() + " " + accdate_256.Hour.ToString() + ":" + accdate_256.Minute.ToString() + ":" + accdate_256.Second.ToString();

                                Mdl_Class.ChannelDataList[(byte)accdate_256.ChannelId].Add(cls_data_256);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_256.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_256.ChannelId].Concat(accdate_256.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 512:

                            Acceleration_512 accdate_512 = (Acceleration_512)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_512.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_512.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_512;
                                Mdl_Class.onlinchannelData.Add(accdate_512);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_512.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_512);
                                }
                                if (accdate_512.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_512);
                                }
                                if (accdate_512.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_512);
                                }
                                if (accdate_512.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_512);
                                }
                            }

                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_512.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_512.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_512.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_512.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_512 = new Cls_Data();
                                cls_data_512._1_3octavedB = accdate_512._1_3octavedB.ToList();
                                cls_data_512.AccelerationFFTAmpDB = accdate_512.accelerationFFTAmpDB.ToList();
                                cls_data_512.AccelerationFFTAmpDB_length = accdate_512.accelerationFFTAmpDB.Length;
                                cls_data_512.AccelerationTimewave = accdate_512.accelerationTimewave.ToList();
                                cls_data_512.AccelerationTimewave_Length = accdate_512.accelerationTimewave.Length;
                                cls_data_512.ChannelId = accdate_512.ChannelId;
                                cls_data_512.HighdB = accdate_512.highdB;
                                cls_data_512.LowdB = accdate_512.lowdB;
                                cls_data_512.TestId = Mdl_Class.TestId;
                                cls_data_512.TotaldB = accdate_512.totaldB;
                                cls_data_512.VelocityRMS = accdate_512.velocityRMS;
                                cls_data_512.TestTime = accdate_512.Year.ToString() + "/" + accdate_512.Month.ToString() + "/" + accdate_512.Day.ToString() + " " + accdate_512.Hour.ToString() + ":" + accdate_512.Minute.ToString() + ":" + accdate_512.Second.ToString();

                                Mdl_Class.ChannelDataList[(byte)accdate_512.ChannelId].Add(cls_data_512);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_512.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_512.ChannelId].Concat(accdate_512.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 1024:

                            Acceleration_1024 accdate_1024 = (Acceleration_1024)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_1024.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_1024.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_1024;
                                Mdl_Class.onlinchannelData.Add(accdate_1024);
                            }
                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_1024.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_1024);
                                }
                                if (accdate_1024.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_1024);
                                }
                                if (accdate_1024.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_1024);
                                }
                                if (accdate_1024.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_1024);
                                }
                            }

                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_1024.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_1024.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_1024.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_1024.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_1024 = new Cls_Data();
                                cls_data_1024._1_3octavedB = accdate_1024._1_3octavedB.ToList();
                                cls_data_1024.AccelerationFFTAmpDB = accdate_1024.accelerationFFTAmpDB.ToList();
                                cls_data_1024.AccelerationFFTAmpDB_length = accdate_1024.accelerationFFTAmpDB.Length;
                                cls_data_1024.AccelerationTimewave = accdate_1024.accelerationTimewave.ToList();
                                cls_data_1024.AccelerationTimewave_Length = accdate_1024.accelerationTimewave.Length;
                                cls_data_1024.ChannelId = accdate_1024.ChannelId;
                                cls_data_1024.HighdB = accdate_1024.highdB;
                                cls_data_1024.LowdB = accdate_1024.lowdB;
                                cls_data_1024.TestId = Mdl_Class.TestId;
                                cls_data_1024.TotaldB = accdate_1024.totaldB;
                                cls_data_1024.VelocityRMS = accdate_1024.velocityRMS;
                                cls_data_1024.TestTime = accdate_1024.Year.ToString() + "/" + accdate_1024.Month.ToString() + "/" + accdate_1024.Day.ToString() + " " + accdate_1024.Hour.ToString() + ":" + accdate_1024.Minute.ToString() + ":" + accdate_1024.Second.ToString();

                                Mdl_Class.ChannelDataList[(byte)accdate_1024.ChannelId].Add(cls_data_1024);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_1024.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_1024.ChannelId].Concat(accdate_1024.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 2048:
                            Acceleration_2048 accdate_2048 = (Acceleration_2048)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_2048.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_2048.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_2048;
                                Mdl_Class.onlinchannelData.Add(accdate_2048);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_2048.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_2048);
                                }
                                if (accdate_2048.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_2048);
                                }
                                if (accdate_2048.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_2048);
                                }
                                if (accdate_2048.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_2048);
                                }
                            }
                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_2048.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_2048.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_2048.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_2048.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_2048 = new Cls_Data();
                                cls_data_2048._1_3octavedB = accdate_2048._1_3octavedB.ToList();
                                cls_data_2048.AccelerationFFTAmpDB = accdate_2048.accelerationFFTAmpDB.ToList();
                                cls_data_2048.AccelerationFFTAmpDB_length = accdate_2048.accelerationFFTAmpDB.Length;
                                cls_data_2048.AccelerationTimewave = accdate_2048.accelerationTimewave.ToList();
                                cls_data_2048.AccelerationTimewave_Length = accdate_2048.accelerationTimewave.Length;
                                cls_data_2048.ChannelId = accdate_2048.ChannelId;
                                cls_data_2048.HighdB = accdate_2048.highdB;
                                cls_data_2048.LowdB = accdate_2048.lowdB;
                                cls_data_2048.TestId = Mdl_Class.TestId;
                                cls_data_2048.TotaldB = accdate_2048.totaldB;
                                cls_data_2048.VelocityRMS = accdate_2048.velocityRMS;
                                cls_data_2048.TestTime = accdate_2048.Year.ToString() + "/" + accdate_2048.Month.ToString() + "/" + accdate_2048.Day.ToString() + " " + accdate_2048.Hour.ToString() + ":" + accdate_2048.Minute.ToString() + ":" + accdate_2048.Second.ToString();

                                Mdl_Class.ChannelDataList[(byte)accdate_2048.ChannelId].Add(cls_data_2048);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_2048.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_2048.ChannelId].Concat(accdate_2048.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 4096:
                            Acceleration_4096 accdate_4096 = (Acceleration_4096)Mdl_Class.accdatalist.ToArray()[i];
                            if (Mdl_Class.OnLineChannelId == accdate_4096.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_4096;
                                Mdl_Class.onlinchannelData.Add(accdate_4096);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_4096.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_4096);
                                }
                                if (accdate_4096.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_4096);
                                }
                                if (accdate_4096.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_4096);
                                }
                                if (accdate_4096.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_4096);
                                }
                            }

                            Console.WriteLine("接收到通道：" + accdate_4096.ChannelId.ToString() + "数据");
                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_4096.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_4096.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_4096.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_4096.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_4096 = new Cls_Data();
                                cls_data_4096._1_3octavedB = accdate_4096._1_3octavedB.ToList();
                                cls_data_4096.AccelerationFFTAmpDB = accdate_4096.accelerationFFTAmpDB.ToList();
                                cls_data_4096.AccelerationFFTAmpDB_length = accdate_4096.accelerationFFTAmpDB.Length;
                                cls_data_4096.AccelerationTimewave = accdate_4096.accelerationTimewave.ToList();
                                cls_data_4096.AccelerationTimewave_Length = accdate_4096.accelerationTimewave.Length;
                                cls_data_4096.ChannelId = accdate_4096.ChannelId;
                                cls_data_4096.HighdB = accdate_4096.highdB;
                                cls_data_4096.LowdB = accdate_4096.lowdB;
                                cls_data_4096.TestId = Mdl_Class.TestId;
                                cls_data_4096.TotaldB = accdate_4096.totaldB;
                                cls_data_4096.VelocityRMS = accdate_4096.velocityRMS;
                                cls_data_4096.TestTime = accdate_4096.Year.ToString() + "/" + accdate_4096.Month.ToString() + "/" + accdate_4096.Day.ToString() + " " + accdate_4096.Hour.ToString() + ":" + accdate_4096.Minute.ToString() + ":" + accdate_4096.Second.ToString();

                                Mdl_Class.ChannelDataList[(byte)accdate_4096.ChannelId].Add(cls_data_4096);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_4096.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_4096.ChannelId].Concat(accdate_4096.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 8192:
                            Acceleration_8192 accdate_8192 = (Acceleration_8192)Mdl_Class.accdatalist.ToArray()[i];
                            if (Mdl_Class.OnLineChannelId == accdate_8192.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_8192;
                                Mdl_Class.onlinchannelData.Add(accdate_8192);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_8192.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_8192);
                                }
                                if (accdate_8192.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_8192);
                                }
                                if (accdate_8192.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_8192);
                                }
                                if (accdate_8192.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_8192);
                                }
                            }
                            Console.WriteLine("接收到通道：" + accdate_8192.ChannelId.ToString() + "数据");
                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_8192.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_8192.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_8192.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_8192.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_8192 = new Cls_Data();
                                cls_data_8192._1_3octavedB = accdate_8192._1_3octavedB.ToList();
                                cls_data_8192.AccelerationFFTAmpDB = accdate_8192.accelerationFFTAmpDB.ToList();
                                cls_data_8192.AccelerationFFTAmpDB_length = accdate_8192.accelerationFFTAmpDB.Length;
                                cls_data_8192.AccelerationTimewave = accdate_8192.accelerationTimewave.ToList();
                                cls_data_8192.AccelerationTimewave_Length = accdate_8192.accelerationTimewave.Length;
                                cls_data_8192.ChannelId = accdate_8192.ChannelId;
                                cls_data_8192.HighdB = accdate_8192.highdB;
                                cls_data_8192.LowdB = accdate_8192.lowdB;
                                cls_data_8192.TestId = Mdl_Class.TestId;
                                cls_data_8192.TotaldB = accdate_8192.totaldB;
                                cls_data_8192.VelocityRMS = accdate_8192.velocityRMS;
                                cls_data_8192.TestTime = accdate_8192.Year.ToString() + "/" + accdate_8192.Month.ToString() + "/" + accdate_8192.Day.ToString() + " " + accdate_8192.Hour.ToString() + ":" + accdate_8192.Minute.ToString() + ":" + accdate_8192.Second.ToString();
                                Mdl_Class.ChannelDataList[(byte)accdate_8192.ChannelId].Add(cls_data_8192);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_8192.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_8192.ChannelId].Concat(accdate_8192.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 16384:
                            Acceleration_16384 accdate_16384 = (Acceleration_16384)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_16384.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_16384.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_16384;
                                Mdl_Class.onlinchannelData.Add(accdate_16384);
                            }
                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_16384.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_16384);
                                }
                                if (accdate_16384.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_16384);
                                }
                                if (accdate_16384.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_16384);
                                }
                                if (accdate_16384.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_16384);
                                }
                            }
                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_16384.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_16384.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_16384.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_16384.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_16384 = new Cls_Data();
                                cls_data_16384._1_3octavedB = accdate_16384._1_3octavedB.ToList();
                                cls_data_16384.AccelerationFFTAmpDB = accdate_16384.accelerationFFTAmpDB.ToList();
                                cls_data_16384.AccelerationFFTAmpDB_length = accdate_16384.accelerationFFTAmpDB.Length;
                                cls_data_16384.AccelerationTimewave = accdate_16384.accelerationTimewave.ToList();
                                cls_data_16384.AccelerationTimewave_Length = accdate_16384.accelerationTimewave.Length;
                                cls_data_16384.ChannelId = accdate_16384.ChannelId;
                                cls_data_16384.HighdB = accdate_16384.highdB;
                                cls_data_16384.LowdB = accdate_16384.lowdB;
                                cls_data_16384.TestId = Mdl_Class.TestId;
                                cls_data_16384.TotaldB = accdate_16384.totaldB;
                                cls_data_16384.VelocityRMS = accdate_16384.velocityRMS;
                                cls_data_16384.TestTime = accdate_16384.Year.ToString() + "/" + accdate_16384.Month.ToString() + "/" + accdate_16384.Day.ToString() + " " + accdate_16384.Hour.ToString() + ":" + accdate_16384.Minute.ToString() + ":" + accdate_16384.Second.ToString();
                                Mdl_Class.ChannelDataList[(byte)accdate_16384.ChannelId].Add(cls_data_16384);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_16384.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_16384.ChannelId].Concat(accdate_16384.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 32768:
                            Acceleration_32768 accdate_32768 = (Acceleration_32768)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_32768.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_32768.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_32768;
                                Mdl_Class.onlinchannelData.Add(accdate_32768);
                            }

                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_32768.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_32768);
                                }
                                if (accdate_32768.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_32768);
                                }
                                if (accdate_32768.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_32768);
                                }
                                if (accdate_32768.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_32768);
                                }
                            }
                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_32768.ChannelId))
                            {
                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_32768.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_32768.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_32768.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_32768 = new Cls_Data();
                                cls_data_32768._1_3octavedB = accdate_32768._1_3octavedB.ToList();
                                cls_data_32768.AccelerationFFTAmpDB = accdate_32768.accelerationFFTAmpDB.ToList();
                                cls_data_32768.AccelerationFFTAmpDB_length = accdate_32768.accelerationFFTAmpDB.Length;
                                cls_data_32768.AccelerationTimewave = accdate_32768.accelerationTimewave.ToList();
                                cls_data_32768.AccelerationTimewave_Length = accdate_32768.accelerationTimewave.Length;
                                cls_data_32768.ChannelId = accdate_32768.ChannelId;
                                cls_data_32768.HighdB = accdate_32768.highdB;
                                cls_data_32768.LowdB = accdate_32768.lowdB;
                                cls_data_32768.TestId = Mdl_Class.TestId; ;
                                cls_data_32768.TotaldB = accdate_32768.totaldB;
                                cls_data_32768.VelocityRMS = accdate_32768.velocityRMS;
                                cls_data_32768.TestTime = accdate_32768.Year.ToString() + "/" + accdate_32768.Month.ToString() + "/" + accdate_32768.Day.ToString() + " " + accdate_32768.Hour.ToString() + ":" + accdate_32768.Minute.ToString() + ":" + accdate_32768.Second.ToString();
                                Mdl_Class.ChannelDataList[(byte)accdate_32768.ChannelId].Add(cls_data_32768);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_32768.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_32768.ChannelId].Concat(accdate_32768.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        case 65536:
                            Acceleration_65536 accdate_65536 = (Acceleration_65536)Mdl_Class.accdatalist.ToArray()[i];
                            Console.WriteLine("接收到通道：" + accdate_65536.ChannelId.ToString() + "数据");
                            if (Mdl_Class.OnLineChannelId == accdate_65536.ChannelId && Mdl_Class.TestModel == 2)
                            {
                                Mdl_Class.accdata = accdate_65536;
                                Mdl_Class.onlinchannelData.Add(accdate_65536);
                            }
                            if (Mdl_Class.TestModel == 1)
                            {
                                if (accdate_65536.ChannelId == Mdl_Class.Test1_channel)
                                {
                                    Mdl_Class.Test1_Data.Add(accdate_65536);
                                }
                                if (accdate_65536.ChannelId == Mdl_Class.Test2_channel)
                                {
                                    Mdl_Class.Test2_Data.Add(accdate_65536);
                                }
                                if (accdate_65536.ChannelId == Mdl_Class.Test3_channel)
                                {
                                    Mdl_Class.Test3_Data.Add(accdate_65536);
                                }
                                if (accdate_65536.ChannelId == Mdl_Class.Test4_channel)
                                {
                                    Mdl_Class.Test4_Data.Add(accdate_65536);
                                }
                            }

                            if (!Mdl_Class.ChannelDataCount.ContainsKey((byte)accdate_65536.ChannelId))
                            {

                                break;
                            }
                            else if (Mdl_Class.ChannelDataCount[(byte)accdate_65536.ChannelId] >= Mdl_Class.AverageNO)
                            {
                                break;
                            }
                            Mdl_Class.ChannelDataCount[(byte)accdate_65536.ChannelId]++;
                            if (Mdl_Class.ChannelDataCount[(byte)accdate_65536.ChannelId] == Mdl_Class.AverageNO)
                            {
                                Cls_Data cls_data_65536 = new Cls_Data();
                                cls_data_65536._1_3octavedB = accdate_65536._1_3octavedB.ToList();
                                cls_data_65536.AccelerationFFTAmpDB = accdate_65536.accelerationFFTAmpDB.ToList();
                                cls_data_65536.AccelerationFFTAmpDB_length = accdate_65536.accelerationFFTAmpDB.Length;
                                cls_data_65536.AccelerationTimewave = accdate_65536.accelerationTimewave.ToList();
                                cls_data_65536.AccelerationTimewave_Length = accdate_65536.accelerationTimewave.Length;
                                cls_data_65536.ChannelId = accdate_65536.ChannelId;
                                cls_data_65536.HighdB = accdate_65536.highdB;
                                cls_data_65536.LowdB = accdate_65536.lowdB;
                                cls_data_65536.TestId = Mdl_Class.TestId;
                                cls_data_65536.TotaldB = accdate_65536.totaldB;
                                cls_data_65536.VelocityRMS = accdate_65536.velocityRMS;
                                cls_data_65536.TestTime = accdate_65536.Year.ToString() + "/" + accdate_65536.Month.ToString() + "/" + accdate_65536.Day.ToString() + " " + accdate_65536.Hour.ToString() + ":" + accdate_65536.Minute.ToString() + ":" + accdate_65536.Second.ToString();
                                Mdl_Class.ChannelDataList[(byte)accdate_65536.ChannelId].Add(cls_data_65536);
                            }
                            Mdl_Class.ChannelOldDataList[(byte)accdate_65536.ChannelId] = Mdl_Class.ChannelOldDataList[(byte)accdate_65536.ChannelId].Concat(accdate_65536.accelerationTimewave.ToList()).ToList<float>();
                            Mdl_Class.TestProgress++;
                            break;
                        default:
                            break;
                    }
                    //}
                    Mdl_Class.accdatalist.RemoveAt(0);

                    if (Mdl_Class.TestModel == 2)
                    {
                        bool countisok = true;
                        foreach (var item in Mdl_Class.ChannelDataCount.Keys)
                        {
                            if (Mdl_Class.ChannelDataCount[item] < Mdl_Class.AverageNO)
                            {
                                countisok = false;
                                break;
                            }
                        }

                        if (countisok)
                        {
                            //AccData accdate = Mdl_Class.accdatalist.ToArray()[0];
                            //Mdl_Class.accdatalist.RemoveAt(0);
                            oper_data.AddData(Mdl_Class.ChannelDataList);
                            Cls_Test clstst = new Cls_Test();
                            clstst.TestId = Mdl_Class.TestId;
                            clstst.TestName = Mdl_Class.TestName;
                            clstst.SectionId = Mdl_Class.NowRunTestStectionId;
                            clstst.WindowFunction = Mdl_Class.WindowFunction_Name;
                            clstst.SampFreq = Mdl_Class.SampFreq.ToString();
                            clstst.AverageMod = Mdl_Class.AverageMod_Name;
                            clstst.AverageNO = Mdl_Class.AverageNO.ToString();
                            clstst.CreatDate = DateTime.Now;
                            clstst.LineNO = Mdl_Class.LineNO.ToString();
                            oper_test.AddTest(clstst);
                            Cls_RunSet clsrunset = new Cls_RunSet();
                            clsrunset.BandWidth = Mdl_Class.SampFreq.ToString();
                            clsrunset.TestId = Mdl_Class.TestId;
                            clsrunset.AverageModel = Mdl_Class.AverageMod_Name;
                            clsrunset.SpecLines = Mdl_Class.LineNO.ToString();
                            clsrunset.Resolution = Math.Round(Convert.ToDouble(Mdl_Class.SampFreq) / Convert.ToDouble(Mdl_Class.LineNO), 3).ToString();
                            clsrunset.WindowFun = Mdl_Class.WindowFunction_Name;
                            clsrunset.NumAverage = Mdl_Class.AverageNO.ToString();
                            operunset.AddRunSet(clsrunset);
                            foreach (byte item in Mdl_Class.ChannelOldDataList.Keys)
                            {

                                Common.DBOper.Cls_Channel channelset = opchannel.GetChannelBySectionId(Mdl_Class.NowRunTestStectionId, item);
                                string filePath = Mdl_Class.FilePath.Split('.')[0] + "\\" + Mdl_Class.NowStectionName + "\\" + Mdl_Class.TestName;
                                string fileName = "原始数据_" + channelset.TestPointName + ".ini";
                                string result = String.Join(",", Mdl_Class.ChannelOldDataList[item]);
                                optxt.WriteTXT(filePath, fileName, result);
                            }
                            Mdl_Class.TestProgress++;
                            Mdl_Class.IsQuitProgram = true;
                            break;
                        }
                        //List<float>  dataslist=op_acc.GetDataByFieldName("TotaldB",-1,1,"","",-1,-1);
                    }
                }
                Thread.Sleep(5);

                }
                catch (Exception)
                {

                    //throw;
                }
            } while (true);
       
        }

        public void SaveDisplacementData()
        {
            do
            {
                try
                {

          
                if (Mdl_Class.IsQuitProgram)
                {
                    break;
                }
                if (Mdl_Class.displacementDatalist.Count > 0)
                {
                        DisplacementData displacedata = Mdl_Class.displacementDatalist.ToArray()[0];
                        Mdl_Class.displacementDatalist.RemoveAt(0);
                        op_displace.AddDisplacementDataInfo(displacedata);
  
             
                }
                }
                catch (Exception)
                {

                    //throw;
                }
                Thread.Sleep(5);
            } while (true);
        }

        public void SaveSlowSignal()
        {
            do
            {
                try
                {


                    if (Mdl_Class.IsQuitProgram)
                    {
                        break;
                    }
                    if (Mdl_Class.slowSignallist.Count > 0)
                    {
                        SlowSignal slowsignaldata = Mdl_Class.slowSignallist.ToArray()[0];
                        Mdl_Class.slowSignallist.RemoveAt(0);
                        op_slow.AddSlowSignalInfo(slowsignaldata);
                    }
                }
                catch (Exception)
                {

                    //throw;
                }
                Thread.Sleep(5);
            } while (true);
        }

        public void SaveSpeedData()
        {
            do
            {
                try
                {


                    if (Mdl_Class.IsQuitProgram)
                    {
                        break;
                    }
                    if (Mdl_Class.speedDatalist.Count > 0)
                    {
                        SpeedData speeddata = Mdl_Class.speedDatalist.ToArray()[0];
                        Mdl_Class.speedDatalist.RemoveAt(0);
                        op_speed.AddSpeedDataInfo(speeddata);


                    }
                }
                catch (Exception)
                {

                    //throw;
                }
                Thread.Sleep(5);
            } while (true);
        }

        public void SaveSamplingConfig()
        {
            do
            {
                try
                {

                    if (Mdl_Class.IsQuitProgram)
                    {
                        break;
                    }
                    if (Mdl_Class.SamplingConfiglist.Count > 0)
                    {
                        SamplingConfig speedrealdata = Mdl_Class.SamplingConfiglist.ToArray()[0];
                        Mdl_Class.SamplingConfiglist.RemoveAt(0);
                        op_vol.AddSamplingConfigInfo(speedrealdata);
                    }
                }
                catch (Exception)
                {

                    //throw;
                }
                Thread.Sleep(5);
            } while (true);
        }

        public void SaveMachineTime(MachineTime datas)
        {

        }
    }
}
